<script setup lang='ts'>
import ChannelNav from '@/components/ChannelNav.vue';
import ArticleList from '@/components/ArticleList.vue';
import { onMounted, ref } from 'vue';
import { getChannelAPI } from '@/api/channel';
import type { ChannelItem } from '@/types';

onMounted(() => {
    // 获取频道数据
    getChannel()
})
const channelList = ref<ChannelItem[]>([])

const updataActiveId = (id: number) => {
    activeId.value = id
}

// 激活id
const activeId = ref(0)
const getChannel = async () => {
    const result = await getChannelAPI()
    channelList.value = result.channels // 赋值列表
    activeId.value = result.channels[0].id // 默认激活第一个 把第一个频道的id作为激活的选项
}
</script>

<template>
    <!-- 频道 -->
    <ChannelNav :active-id="activeId" :channels="channelList" @updata-active-id="updataActiveId"></ChannelNav>
    <!-- 列表 -->
    <ArticleList></ArticleList>

</template>

<style scoped></style>